package com.wang.cloud.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wang.cloud.common.core.api.ApiResult;
import com.wang.cloud.manage.domain.co.*;
import com.wang.cloud.manage.domain.vo.*;
import com.wang.cloud.manage.service.IRoleService;
import com.wang.cloud.manage.service.manage.RoleManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统-角色信息表 前端控制器
 * </p>
 *
 * @author wy
 * @since 2024-07-15
 */
@Tag(name = "系统-角色信息")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/role")
public class RoleController {

    private final IRoleService service;

    private final RoleManageService manageService;

    @Operation(summary = "分页查询")
    @GetMapping("page")
    public ApiResult<IPage<RolePageVo>> page(RolePageCo pageCo) {
        return ApiResult.success(service.page(pageCo));
    }

    @Operation(summary = "获取所有角色下拉列表")
    @GetMapping("list/select")
    public ApiResult<List<SelectVo<Long>>> allSelectList() {
        return ApiResult.success(service.allSelectList());
    }


    @Operation(summary = "查询角色详情")
    @GetMapping("info")
    public ApiResult<RoleDetailVo> queryInfo(@RequestParam Long roleId) {
        return ApiResult.success(manageService.queryInfo(roleId));
    }

    @Operation(summary = "查询角色拥有的菜单树")
    @GetMapping("menu/tree")
    public ApiResult<List<MenuTreeVo>> getMenuTree(@RequestParam Long roleId) {
        return ApiResult.success(manageService.getMenuTree(roleId));
    }

    @Operation(summary = "查询角色拥有的菜单id")
    @GetMapping("menu/ids")
    public ApiResult<RoleMenuIdsVo> getMenuIds(@RequestParam Long roleId) {
        return ApiResult.success(manageService.getMenuIds(roleId));
    }

    @Operation(summary = "新增角色")
    @PostMapping("add")
    public ApiResult addRole(@Validated @RequestBody RoleAddCo co) {
        manageService.addRole(co);
        return ApiResult.success();
    }

    @Operation(summary = "更新角色信息")
    @PostMapping("update")
    public ApiResult updateRole(@Validated @RequestBody RoleUpdateCo co) {
        manageService.updateRole(co);
        return ApiResult.success();
    }

    @Operation(summary = "更新角色状态")
    @PostMapping("status/update")
    public ApiResult updateRoleStatus(@Validated @RequestBody UpdateStatusCo co) {
        manageService.updateRoleStatus(co);
        return ApiResult.success();
    }

    @Operation(summary = "删除角色")
    @DeleteMapping("del")
    public ApiResult delRole(@Validated @RequestBody IdCo delCo) {
        manageService.delRole(delCo);
        return ApiResult.success();
    }
}
